import { getConfig } from './services'

const { APP_ENV } = process.env
const publicPath = APP_ENV === 'local' ? '/' : '/yuantu/h5-app/'

// 版本号控制
const syncLoadJs = (version = '') => new Promise((resolve, reject) => {
  const oScript = document.createElement('script');
  oScript.setAttribute('src', `${publicPath}${version}/index.bundle.js`);
  oScript.setAttribute('type', 'text/javascript');
  oScript.onload = resolve();
  oScript.onerror = (err) => reject(err);
  document.body.appendChild(oScript);
})



getConfig().then(res => {
  const config = res.data
  syncLoadJs(config[`base_${APP_ENV}`])
})